# coding = utf-8
"""
WWWDOT-GOOGLE=DOTCOM
每个字符代表一个0-9之间的数字，找出每个字母代表的数字，
使等式成立。
"""


# 字母WDOTGLECM
# WGM [1-9] 其他[0-9]



def checkequal():
    first = int('{W}{W}{W}{D}{O}{T}'.format(W=W, D=D, O=O, T=T))
    second = int('{G}{O}{O}{G}{L}{E}'.format(G=G, O=O, L=L, E=E))
    third = int('{D}{O}{T}{C}{O}{M}'.format(D=D, O=O, T=T, C=C, M=M))
    if first == second + third:
        print('%s-%s=%s' % (first, second, third))


rawnumlist = list(range(0, 10))


def checkisvalid(char: str, number: int):
    if char in 'WGM' and number == 0:
        return False
    return True


# 字母WDOTGLECM
# WGM [1-9] 其他[0-9]
import time

start = time.time()
for i in rawnumlist:
    if i == 0:
        continue
    W = i
    tmplist = rawnumlist.copy()
    tmplist.remove(W)
    # print('tmplist=%s'%tmplist)
    for i in tmplist:
        D = i
        tmplist1 = tmplist.copy()
        tmplist1.remove(D)
        # print('tmplist1=%s' % tmplist1)
        for i in tmplist1:
            O = i
            tmplist2 = tmplist1.copy()
            tmplist2.remove(O)
            # print('tmplist2=%s' % tmplist2)
            for i in tmplist2:
                T = i
                tmplist3 = tmplist2.copy()
                tmplist3.remove(T)
                # print('tmplist3=%s' % tmplist3)
                for i in tmplist3:
                    if i == 0:
                        continue
                    G = i
                    tmplist4 = tmplist3.copy()
                    tmplist4.remove(G)
                    # print('tmplist4=%s' % tmplist4)
                    for i in tmplist4:
                        L = i
                        tmplist5 = tmplist4.copy()
                        tmplist5.remove(L)
                        # print('tmplist5=%s' % tmplist5)
                        for i in tmplist5:
                            E = i
                            tmplist6 = tmplist5.copy()
                            tmplist6.remove(E)
                            # print('tmplist6=%s' % tmplist6)
                            for i in tmplist6:
                                C = i
                                tmplist7 = tmplist6.copy()
                                tmplist7.remove(C)
                                # print('tmplist7=%s' % tmplist7)
                                for i in tmplist7:
                                    if i == 0:
                                        continue
                                    M = i
                                    tmplist8 = tmplist7.copy()
                                    tmplist8.remove(M)
                                    # print('tmplist8=%s' % tmplist8)
                                    checkequal()
end = time.time()
print("Process finished in %f seconds" % (end - start))
